#!/bin/bash
# 级别
#chkchonfig: 2345 80 90
# 描述
#description:can service
# 进程名
#processname:can-servcie

# 所在目录
ROOT_PATH=/home/can/api

RETVAL=0
SERVER_PORT=40001

start()
{ 
 pids=`netstat -lnp | grep $SERVER_PORT |awk '{print $7 }'`
 pids=${pids%/*}
 if [ -n "$pids" ]; then
   echo  "CANAPI SERVICE ALREADY START "
 else
   nohup ./$ROOT_PATH/can_api >$ROOT_PATH/server.log 2>&1 &
   echo "START CANAPI SERVICE SUCCESS "
 fi
}

stop()
{
 echo -n $"Stopping $prog: "
 javac -version
 pids=`netstat -lnp | grep $SERVER_PORT |awk '{print $7 }'`
 pids=${pids%/*}
 if [ -n "$pids" ]; then
    kill -9 $pids
    echo "STOP BUSINESS_MONITOR SUCCESS "
 else
    echo  "BUSINESS_MONITOR SERVICE ALREADY STOP "
 fi
}

restart()
{
 echo -n $"Reloading $prog: "
}

case "$1" in
 start)
  start
  ;;
 stop)
  stop
  ;;
 restart)
  stop
  sleep 2        
  start
  ;;
 *)
 echo "Usage: $0 {start|stop|restart}"
 exit 1
esac
